do_event_describe <- function() {
  
    dt_event_desc <-
      run_query(
        "SELECT  * FROM Expenses_events_for_prediction"
      ) %>%   data.table()
    
    vars_for_pop <- c("id_var", "S_index_date_XX","CNRS_topo_grouped_desc","DMG_age")
    
    pop_cnr <- 
      run_query( sql =   paste0("SELECT  " ,
                               paste(vars_for_pop, collapse = ",") ,
                               " FROM FeaturesExtraction",
                               " WHERE S_sample_source_XX LIKE 'cnr_data' ",
                               "AND( S_index_date_XX < DMG_date_of_death_XX OR DMG_date_of_death_XX IS NULL )")
                ) %>%   data.table()
    
    
    min(pop_cnr$DMG_age)
    length(unique(pop_cnr$id_var))
    
    dt_event_desc_full<- merge(dt_event_desc, 
                          pop_cnr, 
                          by = c("id_var"),
                          all.x = F ,
                          all.y = T )
    
    dt_event_desc_full[is.na(category),category := "no_events"]
    
    dt_event_desc_full[,days_from_dx :=  as.numeric(difftime(event_date,
                                                        as.Date(id_var.x), 
                                                        units = "days")) ]
    
    table_1_events<-rbind(  dt_event_desc_full[,
                                         .('Number of Observations' = scales::comma(.N),
                                           'Number of Unique Patients ' = scales::comma(length(unique(S_teudat_zehut_XX))), 
                                           'Number of Events per Patient (mean)' = round(.N/length(unique(dt_event_desc_full$S_teudat_zehut_XX)),2),
                                           'Probability of Had Any Event' = round(length(unique(S_teudat_zehut_XX))/length(unique(dt_event_desc_full$S_teudat_zehut_XX)),2),
                                           'Days From Date of Diagnosis (mean)' = round(mean(days_from_dx),1)
                                         ),
                                         by  = category],
    dt_event_desc_full[,
                       .('Number of Observations' = scales::comma(.N),
                         'Number of Unique Patients ' = scales::comma(length(unique(S_teudat_zehut_XX))), 
                         'Number of Events per Patient (mean)' = round(.N/length(unique(dt_event_desc_full$S_teudat_zehut_XX)),2),
                         'Probability of Had Any Event' = round(length(unique(S_teudat_zehut_XX))/length(unique(dt_event_desc_full$S_teudat_zehut_XX)),2),
                         'Days From Date of Diagnosis (mean)' = round(mean(days_from_dx,na.rm = T),1)
                       )][ ,category:="Total"]
    )
    table_1_events[,category:=tools::toTitleCase(gsub("_"," ",category))]
    
    table_1_events[8, 2] <-NA_character_
    table_1_events[8, 4] <-NA
    
    
    library(knitr)
    library(kableExtra)
    options(knitr.kable.NA = '.')
    
    
    t(table_1_events) %>%
      kable("latex", booktabs = T, align = "c") %>%
      kable_styling(full_width = F ) %>%
      write("table1_cancer_events.tex")
    
    table_1_events

}
